﻿using Markdig;

namespace MarkdownViewerLib
{
    public partial class MdViewer : UserControl
    {
        public MdViewer()
        {
            InitializeComponent();
        }

        MarkdownPipeline pipeline
        {
            get
            {
                if (_pipe == null)
                {
                    _pipe = new MarkdownPipelineBuilder()
                .UseAdvancedExtensions()
                .UseEmphasisExtras()
                .UseCustomContainers()
                .UseAutoIdentifiers()
                .UsePipeTables()
                .UseFooters()
                .UseListExtras()
                .Build();

                }
                return _pipe;
            }
        }
        MarkdownPipeline _pipe;


        public async Task ViewMarkdown(string md)
        {
            await webViewer.EnsureCoreWebView2Async();


            string html = Markdown.ToHtml(md, pipeline);
            webViewer.CoreWebView2.NavigateToString(html);
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {

        }
    }
}
